package com.lcz.cloud_note.controller;

import javax.annotation.Resource;

import com.lcz.cloud_note.entity.Share;
import com.lcz.cloud_note.service.ShareService;
import com.lcz.cloud_note.util.Result;
import org.springframework.web.bind.annotation.RequestMapping;

import com.lcz.cloud_note.entity.Note;
import com.lcz.cloud_note.service.NoteService;
import com.lcz.cloud_note.util.NoteResult;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/note")
public class NoteController
{
	@Resource
	private NoteService noteService;
	@Resource
	private ShareService shareService;

	@RequestMapping("/add.do")
	public NoteResult<Note> add(String userId,String bookId,String title){
		NoteResult<Note> result = noteService.addNote(userId, bookId, title);
		return result;
	}

	@RequestMapping("/delete")
	public NoteResult delete(String noteId){
		NoteResult result=noteService.deleteNote(noteId);
		return result;
	}

	@RequestMapping("/update.do")
	public NoteResult<Object>  update(String noteId,String title,String body){
		NoteResult<Object> result = noteService.updateNote(noteId, title, body);
		return result;
	}

	@RequestMapping("/load.do")
	public NoteResult<Note> load(String noteId){
		NoteResult<Note> result = noteService.loadNote(noteId);
		return result;
	}

	@RequestMapping("/move")
	public Result execute(String noteId,String bookId){
		return noteService.moveNote(noteId, bookId);
	}

	@RequestMapping("/load_share")
	public NoteResult<Share> loadShare(String shareId){
		NoteResult<Share> result = shareService.loadShareNote(shareId);
		return result;
	}


	@RequestMapping("/loadnotes.do")
	public NoteResult<List<Map>> loadNotes(String bookId){
		NoteResult<List<Map>> result = noteService.loadBookNotes(bookId);
		return result;
	}

	/**
	 * 分享笔记
	 */
	@RequestMapping("/share.do")
	public Result share(String noteId){
		return shareService.shareNote(noteId);
	}

	/**
	 * 搜索笔记
	 */
	@RequestMapping("/search.do")
	public NoteResult<List<Share>> search(String keyword,int page){
		NoteResult<List<Share>> result = shareService.searchNote(keyword,page);
		return result;
	}
	/**
	 * 加载回收站笔记
	 */
	@RequestMapping("/rollback.do")
	public Result rollback(String userId){
		return noteService.rollback(userId);
	}
	/**
	 * 恢复回收站笔记
	 */
	@RequestMapping("/recover.do")
	public Result recover(String userId,String noteId,String bookId){
		return noteService.recover(userId,noteId,bookId);
	}
	/**
	 * 删除回收站笔记
	 */
	@RequestMapping("/remove.do")
	public Result pack(String userId,String noteId){
		return noteService.remove(userId,noteId);
	}

	/**
	 * 收藏分享的笔记
	 */
	@RequestMapping("/collect.do")
	public Result collect(String userId,String shareId){
		return shareService.collect(userId,shareId);
	}
	/**
	 * 加载收藏笔记
	 */
	@RequestMapping("/loanCollect.do")
	public Result loanCollect(String userId){
		return shareService.loanCollect(userId);
	}
	/**
	 * 显示收藏笔记
	 */
	@RequestMapping("/showCollect.do")
	public Result showCollect(String likeId){
		return shareService.showCollect(likeId);
	}
	/**
	 * 删除收藏笔记
	 */
	@RequestMapping("/removeCollect.do")
	public Result removeCollect(String likeId){
		return shareService.removeCollect(likeId);
	}

	/**
	 * 收藏活动的笔记
	 */
	@RequestMapping("/collectForAction.do")
	public Result collectForAction(String userId,String actionDetailId){
		return shareService.collectForAction(userId,actionDetailId);
	}
}
